package com.googlecode.gwtCorsForIe8.client;

import com.google.gwt.http.client.Request;

/**
 * Original from
 * http://experienceswithgwt.blogspot.com/2010/04/gwt-and-cross-site
 * -requests_28.html
 * 
 * @author Sebastian
 */
public class IECrossSiteRequest extends Request {
	static final int UNSENT = 0;
	static final int OPEN = 1;
	static final int SENT = 2;
	static final int DONE = 3;
	private int _status = UNSENT;
	private XDomainRequest _xhr;

	void setStatus(int status) {
		_status = status;
	}

	public IECrossSiteRequest(XDomainRequest xhr) {
		if (xhr == null) {
			throw new NullPointerException();
		}
		_xhr = xhr;
	}

	public void cancel() {
		if (isPending()) {
			_xhr.abort();
		}
	}

	public boolean isPending() {
		return (_status == OPEN || _status == SENT);
	}
}